package com.jiao.Controller;

import com.jiao.Aspect.ApiLog;
import com.jiao.domain.DTO.CommentDto;
import com.jiao.domain.Result;
import com.jiao.domain.VO.PageVo;
import com.jiao.service.CommentService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;

/*
* 对于返回值,那就直接看前后端约定即可。主要是  接口名称 + URL、入参
* */
@RestController
@Validated
@Api(tags = "删除接口")
@RequestMapping("/comment")
public class CommentController {

    @Autowired
    private CommentService commentService;

    /*
    * ● paramType：告诉前端参数放哪，有header、query、path、body和form
    * ● required：告诉前端该参数是否必传
    * ● defaultValue：告诉前端如果这个参数不传的话，后端默认值是啥
    * */
    @ApiLog
    @ApiOperation(value = "遍历文章下所有评论")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "articleId", value = "文章id", dataType = "String", paramType = "query", required = true),
            @ApiImplicitParam(name = "pageNum", value = "页号", dataType = "Integer", paramType = "query", required = true),
            @ApiImplicitParam(name = "pageSize", value = "每页数量", dataType = "Integer", paramType = "query", required = true)
    })
    @GetMapping("/commentList")
    public Result<PageVo> commentList(@NotNull(message = "文章id不能为空")  Long articleId,
                                       Integer pageNum,
                                       Integer pageSize){
        return commentService.AllCommentList(articleId,pageNum,pageSize);
    }
    @ApiOperation(value = "插入评论")
    @PostMapping("/insertCommentt")
    public Result<String> insertCommentt(@RequestBody CommentDto commentDto){
        return commentService.insertCommentt(commentDto);
    }
}